<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="~/MainSys/Manager/Controls/ctManagementOrg.ascx.cs" Inherits="KhoaLuan.MainSys.Manager.Controls.ctManagementOrg" %>
<link href="../../../Style/StyleCommon.css" rel="stylesheet" />
<link href="../../../Style/modal.css" rel="stylesheet" />
<script src="/Scripts/dluscript.js"></script>
<script type="text/javascript">
    var currentOrg;
    var _listOrg = [];
    function GetOrgInList(orgId) {
        for (var i = 0; i < _listOrg.length; i++) {
            if (_listOrg[i].OrgID == orgId)
                return _listOrg[i];
        }
        return null;
    }
 
    function LoadListOrg(totalitem, target, listOrg) {
        _listOrg = listOrg;
        debugger;
        target.empty();
        _listOrg.forEach(function (item) {
                var tr = $("<tr>");
                var td = $("<td>").append($('<input type="checkbox">'));
                tr.append(td);
                td = $("<td>").text(item.NameOrg);
                tr.append(td);
                td = $("<td>").text(item.TypeOrg);
                tr.append(td);
                td = $("<td>");
                var btnedit = CreateButton(item.OrgID, "fa-edit");
                btnedit.click(function () {
                    currentOrg = GetOrgInList($(this).attr('dataid'));
                    var target = "/MainSys/Manager/Org/AddNewOrg.aspx";
                    $('#remoteModal').removeData();
                    $("#remoteModal").load(target, function () {
                        $("#remoteModal").modal("show");
                    });
                });
                td.append(btnedit);

                var btndel = CreateButton(item.OrgID, "fa-times");
                btndel.click(function () {
                    debugger;
                    var id = $(this).attr("dataid");
                    var sender = $(this);
                    confirm("Xác nhận", "Bạn có muốn xóa org này không", "Xóa", "Hủy bỏ", function () {
                        debugger;
                        CallAjaxAspx("POST", "DeleteOrg", "/MainSys/ProcessAJAX/AjaxOrg.aspx", { OrgID: parseInt(id) }, function (data) {
                            debugger;
                            var responseDel = JSON.parse(data);

                            if (responseDel.Status) {
                                debugger;
                                sender.parent().parent().remove();
                                alertSmallBox("Xóa Org thành công", "1 giây trước...");
                            }
                            else {
                                alertSmallBox("Xóa Org thất bại", "1 giây trước...", "error");
                            }
                        }, function () { }, function () { });
                    });
                });
                debugger;
                td.append(btndel);
                tr.append(td);
                target.append(tr);
        });
        }

    function LoadData(page) {
        debugger;
        var numberinpage = 5;
        var keyword = $("#<%=txtTimKiem.ClientID%>").val();
        var dataagr = JSON.stringify({
            keyword: keyword,
            currentpage: parseInt(page),
            numberinpage: numberinpage
        });
        LoadDataWithPaging($("#tabletbOrg > tbody"), $("#divpaging"), page, "POST", "/MainSys/ProcessAJAX/AjaxOrg.aspx/GetListOrg", dataagr, LoadListOrg, numberinpage, LoadData);
    }
    $(document).ready(function () {
        debugger;
        LoadData(1);
        $("#<%=btnThem.ClientID%>").click(function () {
            currentOrg = null;
            var target = "/MainSys/Manager/Org/AddNewOrg.aspx";
            $('#remoteModal').removeData();
            $("#remoteModal").load(target, function () {
                $("#remoteModal").modal("show");
            });
        });
     });
        function Import() {
            debugger;
            var datafile = new FormData();
            var files = $("#fileUpload").get(0).files;
            //// Add the uploaded image content to the form data collection
            if (files.length > 0) {
                datafile.append("File", files[0]);
            }
            datafile.append("TableName", "tbOrg");

            // Make Ajax request with the contentType = false, and procesDate = false
            $.ajax({
                type: "POST",
                url: "/ProcessAJAX/AJAXImport.ashx",
                contentType: false,
                processData: false,
                data: datafile,
                success: function (data) {
                    var res = JSON.parse(data);
                    if (res.Status == "Success") {
                        alert("import thanh cong.");
                        LoadTabletbOrg();
                    }
                    else {
                        alert("import that bai.");
                    }
                }
            });

        }

</script>
<div class="jarviswidget jarviswidget-color-blueDark" id="wid-id-1" data-widget-editbutton="false" data-widget-fullscreenbutton="false">

 

    <header>
        <h2>Manage Organization	</h2>
        <div class="widget-toolbar">
            <!-- add: non-hidden - to disable auto hide -->

            <div class="btn-group">
                <input class="btn btnthem dropdown-toggle btn-xs btn-success" type="button" id="btnThem" runat="server" style="margin-right: 10px;" value="Add new" />
                <input type="button" value="Show" class="btn btnthem dropdown-toggle btn-xs btn-success" onclick="LoadData(1)" />
            </div>
        </div>
    </header>

    <div>
        <div class="widget-body widget-hide-overflow padding">
            <div class="col-xs-12 col-sm-6">
                <div id="datatable_tabletools_filter" class="dataTables_filter">
                    <label style="float: left">
                        <span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span>
                        <input type="search" class="form-control" placeholder="input keyword" id="txtTimKiem" runat="server" />
                        <input type="button" onclick="LoadData(1);" value="Search" class="btn btn-default" style="width: 80px;" />
                    </label>
                </div>
            </div>
            <div class="col-sm-6 col-xs-6 hidden-xs" style="text-align: right;">
                <input type="file" id="fileUpload" accept="image/jpg" class="btn btn-default" />
                <input type="button" id="btnImport" runat="server" onclick="Import()" value="import" class="btn btn-default" />
            </div>
            <asp:Label ID="lblThongBao" runat="server" ForeColor="Red"></asp:Label>

            <table id="tabletbOrg" class="table table-bordered">
                <thead>
                    <tr>
                        <td></td>
                        <td>Name of Org
                        </td>
                        <td>Type of Org
                        </td>
                        <td>
                            Action
                        </td>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
        <div id="divpaging"></div>
    </div>

</div>

